package com.kgc.controller;

import com.kgc.service.FindAllSolrService;
import com.kgc.utils.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SolrServiceController {
    @Autowired
    private FindAllSolrService findAllSolrService;

    @RequestMapping("/search")
    public String addToSolr(String q, @RequestParam(value = "page" ,required = false,defaultValue = "1")int  page
    , Model model) throws Exception {
        String queryParam=new String(q.getBytes("iso-8859-1"),"UTF-8");
        SearchResult searchResult = findAllSolrService.queryItemSolr(queryParam, page);
/*        System.out.println(searchResult.getItemList());*/
        model.addAttribute("query",queryParam);
        model.addAttribute("totalPages",searchResult.getTotalPages());
        model.addAttribute("itemList",searchResult.getItemList());
        return "search";
    }



}
